package com.itheima.imclient100.utils;

import android.os.Handler;
import android.os.Looper;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * Created by fullcircle on 2017/7/2.
 */

public class ThreadUtils {
    private static Executor executor = Executors.newSingleThreadExecutor();
    //创建主线程的handler
    private static Handler handler = new Handler(Looper.getMainLooper());

    /**
     * 通过子线程执行runnable
     * @param runnable
     */
    public static void runOnSubThread(Runnable runnable){
        executor.execute(runnable);
    }

    /**
     * 通过主线程执行runnable
     * @param runnable
     */
    public static void runOnMainThread(Runnable runnable){
        handler.post(runnable);
    }
}
